/***************************************************************************
 *   Copyright (C) 2008 by Tomasz Dubik                                    *
 *   tdubik@gmail.com                                                      *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef __FTPHANDLER_H__
#define __FTPHANDLER_H__

#include <QObject>
#include <QPointer>
#include <QFtp>
#include <QProgressDialog>
#include <QFile>

 class FtpHandler : public QObject
{
Q_OBJECT
	public:
		FtpHandler(QObject* parent);
		~FtpHandler();

	public:
		void ftpUpload();
		void ftpDownload();
		bool isDownloading(){ return m_download; };

		void setHost(const QString& host){ m_host = host; };
		void setUsername(const QString& username) { m_username = username; };
		void setPassword(const QString& password) { m_password = password; };
		void setUsePassiveMode(bool use) { m_usePassiveMode = use; };

		QString host(){return m_host; };
		QString username(){ return m_username; };
		QString password(){ return m_password; };
		bool usePassiveMode() { return m_usePassiveMode; };

	private slots:				
		void ftpCommandFinished(int commandId, bool error);
		void updateDataTransferProgress(qint64 readBytes,
										qint64 totalBytes);
		void ftpDone(bool error);

	signals:
		void ftpDone();
		void ftpError(const QString&);
		void ftpProgress(qint64, qint64);
	private:
		void displayError();		
		void uploadFile();
		void downloadFile();
		void connectOrDisconnect();

	private:
		QPointer<QFtp> 				m_ftp;		
		bool						m_download;
		QPointer<QFile>				m_file;
		QString						m_host;
		QString						m_username;
		QString						m_password;
		bool						m_usePassiveMode;
};

#endif //__FTPHANDLER_H__
//eof
